package com.platform.modules.event;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.annotation.SysLog;
import com.platform.common.utils.RestResponse;
import com.platform.modules.event.entity.EventCalendarCategoryEntity;
import com.platform.modules.event.service.EventCalendarCategoryService;
import com.platform.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 分类表Controller
 *
 * @author
 * @date 2020-10-16 09:39:57
 */
@RestController
@RequestMapping("event/category")
public class EventCalendarCategoryController extends AbstractController {
    @Autowired
    private EventCalendarCategoryService eventCalendarCategoryService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("event:category:list")
    public RestResponse queryAll(@RequestParam Map<String, Object> params) {
        List<EventCalendarCategoryEntity> list = eventCalendarCategoryService.queryAll(params);

        return RestResponse.success().put("list", list);
    }

    /**
     * 分页查询模块--分类表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    @RequiresPermissions("event:category:list")
    public RestResponse list(@RequestParam Map<String, Object> params) {
        Page page = eventCalendarCategoryService.queryPage(params);

        return RestResponse.success().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return RestResponse
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("event:category:info")
    public RestResponse info(@PathVariable("id") String id) {
        EventCalendarCategoryEntity Category = eventCalendarCategoryService.getById(id);

        return RestResponse.success().put("category", Category);
    }

    /**
     * 新增模块--分类表
     *
     * @param category
     * @return RestResponse
     */
    @SysLog("新增--分类表")
    @RequestMapping("/save")
    @RequiresPermissions("event:category:save")
    public RestResponse save(@RequestBody EventCalendarCategoryEntity category) {
        if(category.getTitle()==null ||category.getTitle().equals("") ){
            return RestResponse.error("标题不能为空");
        }

        category.setCreateTime(new Date());
        eventCalendarCategoryService.add(category);

        return RestResponse.success();
    }

    /**
     * 修改模块--分类表
     *
     * @param category
     * @return RestResponse
     */
    @SysLog("修改--分类表")
    @RequestMapping("/update")
    @RequiresPermissions("event:category:update")
    public RestResponse update(@RequestBody EventCalendarCategoryEntity category) {

        if(category.getTitle()==null ||category.getTitle().equals("") ){
            return RestResponse.error("标题不能为空");
        }
        category.setUpdateTime(new Date());
        eventCalendarCategoryService.update(category);

        return RestResponse.success();
    }

    /**
     * 根据主键删除模块--分类表
     *
     * @param ids ids
     * @return RestResponse
     */
    @SysLog("删除--分类表")
    @RequestMapping("/delete")
    @RequiresPermissions("event:category:delete")
    public RestResponse delete(@RequestBody String[] ids) {
        eventCalendarCategoryService.deleteBatch(ids);

        return RestResponse.success();
    }
}
